/**
 * Created by wushanxin on 14-3-20.
 */


var http = require('http');

var querystring = require('querystring');


var post_data = {
    apCom: {
        apComHead: {
            action:"init",
            apMac:"00:19:E0:00:00:11",
            apSn:"123",
            gwIp:"127.0.0.1:8888",
            token:"dsadsa"
        },
        apComCont:
        {
            vnoId:"123"
        }
    }};

var options = {
    host: '192.168.1.182',
    port: 8080,
    path: '/',
    method: 'POST'
};


var req = http.request(options, function(res) {
    console.log('STATUS: ' + res.statusCode);
    console.log('HEADERS: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log('BODY: ' + chunk);
    });
});

// write data to request body
function reg(action)
{
    post_data.apCom.apComHead.action=action;
    req.write(JSON.stringify(post_data));
    req.end();
}

var post_data_access = {
    apCom: {
        apComHead: {
            action:"access",
            apMac:"00:19:E0:00:00:11",
            apSn:"123",
            gwIp:"127.0.0.1:8888",
            token:"dsadsa"
        },
        apComCont:
        {
            ip:'192.168.1.4',
            mac:'204C38421900CC468DEBE2DB5F09166D3CCB9F889C4CE9C0',
            sessionId:'182b8b6734472616c77604247baf9b51_10',
            custCode:'',
            ssid:''
        }
    }};
var post_data_online = {
    apCom: {
        apComHead: {
            action:"online",
            apMac:"00:19:E0:00:00:11",
            apSn:"123",
            gwIp:"127.0.0.1:8888",
            token:"dsadsa"
        },
        apComCont:
        {
            ip:'192.168.1.4',
            mac:'204C38421900CC468DEBE2DB5F09166D3CCB9F889C4CE9C0',
            sessionId:'182b8b6734472616c77604247baf9b51_10',
            custCode:'',
            incoming:'11',
            outgoing:'1024'

        }
    }};
function access()
{
    req.write(JSON.stringify(post_data_access));
    req.end();
}
//access();

function online()
{
    req.write(JSON.stringify(post_data_online));
    req.end();
}
//online();



var post_data_counters = {
    apCom: {
        apComHead: {
            action:"counters",
            apMac:"00:19:E0:00:00:11",
            apSn:"123",
            gwIp:"127.0.0.1:8888",
            token:"dsadsa"
        },
        apComCont:
        {
            ip:'192.168.1.4',
            mac:'204C38421900CC468DEBE2DB5F09166D3CCB9F889C4CE9C0',
            sessionId:'182b8b6734472616c77604247baf9b51_10',
            custCode:'',
            upstream:'11',
            downstream:'1024',
            duration:'120'

        }
    }};
function counters()
{
    req.write(JSON.stringify(post_data_counters));
    req.end();
}
//counters();

var post_data_offline = {
    apCom: {
        apComHead: {
            action:"offline",
            apMac:"00:19:E0:00:00:11",
            apSn:"123",
            gwIp:"127.0.0.1:8888",
            token:"dsadsa"
        },
        apComCont:
        {
            ip:'192.168.1.4',
            mac:'204C38421900CC468DEBE2DB5F09166D3CCB9F889C4CE9C0',
            sessionId:'182b8b6734472616c77604247baf9b51_9',
            custCode:'',
            upstream:'11',
            downstream:'1024',
            duration:'120'

        }
    }};
function offline()
{
    req.write(JSON.stringify(post_data_offline));
    req.end();
}
//offline();


//需要依赖的包设置
var express = require('express');
var routes = require('./routes');

var http = require('http');
var path = require('path');
var ejs = require('ejs');
var app = express();
// 设置所有变量及需要使用的变量定义
app.set('ip', "218.244.146.188");//process.env.IP ||  "192.168.1.100");
app.set('port', 8888);//process.env.PORT || 8080);
app.use(app.router); //必须放在这里，否则session无法保存
http.createServer(app).listen(app.get('port'), app.get('ip'), function() {

    console.log('+++++++++++++++++++++++++++++++++++++++++++++++++++');
    console.log('启动服务器完成，IP: '+ app.get('ip') +', Web端口: ' + app.get('port'));
    console.log('+++++++++++++++++++++++++++++++++++++++++++++++++++');
});

app.all('/', function(req,res){
    console.log("接收");
});
